package com.guhappy.action.contest;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.guhappy.model.contest.ContestHome;
import com.guhappy.model.contest.ContestPersonalViewBean;
import com.guhappy.model.user.WebUser;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("default")
@Action(value="contestPersonal",results={@Result(name="success", location="/pages/contestPersonal.jsp")})
public class ContestPersonalAction extends ActionSupport implements ServletRequestAware{
	
	private List<ContestPersonalViewBean> contestviewList = new ArrayList<ContestPersonalViewBean>();
	private String region;
	private String direction;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	HttpServletRequest request;

	@Override
	public String execute() throws Exception {
		if (region==null) 
			region = "0";
		if (direction == null)
			direction = "UP";
		
		contestviewList = ContestHome.buildPersonalContestList(((WebUser)request.getSession().getAttribute("webUser")).getId());
		return SUCCESS;
	}
	
	public List<ContestPersonalViewBean> getContestviewList() {
		return contestviewList;
	}

	public void setContestviewList(List<ContestPersonalViewBean> contestviewList) {
		this.contestviewList = contestviewList;
	}

	public String getRegion() {
		return region;
	}

	public void setRegion(String region) {
		this.region = region;
	}

	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request= arg0;
	}

}
